<?php
namespace app\cms\controller;
use app\common\base\_Db;
use app\common\entity\RequestEntity;
use think\Controller;
use think\Db;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/14
 * Time: 15:23
 */
class Log extends Controller {
    /*
     * 日志
     * 数据列表
     */
    public function ListItem(){
        $request_data = [
            $get_keyword = new RequestEntity('search_key', '搜索内容', false, 0)
        ];
        _Db::Validates($request_data);
        $where = '1=1';
        if(!empty($get_keyword->text)){
            $where .= ' and b.type_name  = "' . $get_keyword->text.'" or c.account = "' . $get_keyword->text.'"';
        }
        $param_page = $get_page = input('Page', 1);
        $param_pagesize = 10;
        $result = Db::table('log')
            ->field(
                [
                    'a.log_id'            => 'Id',	        //主键ID
                    'a.oper_ip'           => 'OperIp',	    //当前IP
                    'a.oper_type'         => 'Type',	    //操作类型
                    'a.oper_content'      => 'Content',	    //操作内容
                    'a.oper_sql'          => 'Sql',	        //执行sql
                    'a.oper_date'         => 'Date',	    //操作时间
                    'b.type_name'         => 'TypeStatus',  //操作状态
                    'c.nick_name'         => 'OperName',  //操作人
                ]
            )
            ->alias('a')
            ->join('sys_public_type b','a.oper_type = b.type_id and b.type_classify = "操作类型"','LEFT')
            ->join('staff c','a.oper_id = c.staff_id','LEFT')
            ->where($where)
            ->limit(($param_page - 1) * $param_pagesize, $param_pagesize)
            ->order('a.oper_date desc')
            ->select();
        //echo Db::table('')->getLastSql();
        foreach ( $result as $key => $value){
            $result[$key]['Order'] = $key + 1;
        };
        $int_total_count = count(Db::table('log')
            ->alias('a')
            ->join('sys_public_type b','a.oper_type = b.type_id and b.type_classify = "操作类型"','LEFT')
            ->join('staff c','a.oper_id = c.staff_id','LEFT')
            ->where($where)
            ->order('a.oper_date desc')
            ->select());
        $data['tableData']=$result;
        $data['TotalCount'] = $int_total_count;
        $data['Page'] = (int)$param_page;
        $data['PageSize'] = (int)$param_pagesize;
        //echo Db::table('')->getLastSql();
        _Db::ResponseJson($data);
    }
}